{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>机构列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-2">
                        <div class="input-group" >
                            <!--<button type="button" class="btn btn-primary btn-outline" data-toggle="modal" data-target="#myModal">添加机构</button> -->
                            <a href="{:url('add_edu')}"><button class="btn btn-outline btn-primary" type="button">添加机构</button></a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="example-wrap">
                <div class="example">
                    <form id="eduorder" name="eduorder" method="post" action="{:url('eduorder')}" >
                        <table class="table table-bordered table-hover">
                            <thead>
                            <tr class="long-tr">
                                <th width="6%">ID</th>
                                <th width="19%">机构名称</th>
                                <!--<th width="17%">节点</th>-->
                                <th width="12%">状态</th>
                                <th width="15%">添加时间</th>
                                <th width="7%">排序</th>
                                <th width="7%">添加子机构</th>
                                <th width="15%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="list" item="v"}
                            <tr class="long-td">
                                <td>{$v.id}</td>
                                <td style='text-align:left;padding-left:{if condition="$v.leftpin neq 0"}{$v.leftpin}px{/if}'>{$v.lefthtml}{$v.name}</td>
                                <!--<td>{$v.name}</td>-->
                                <td>

                                    {if condition="$v.status eq 1"}
                                    <a class="red" href="javascript:;" onclick="edu_state({$v.id});">
                                        <div id="zt{$v.id}"><span class="label label-info">开启</span></div>
                                    </a>
                                    {else/}
                                    <a class="red" href="javascript:;" onclick="edu_state({$v.id});">
                                        <div id="zt{$v.id}"><span class="label label-danger">禁用</span></div>
                                    </a>
                                    {/if}
                                </td>
                                <td>{$v.create_time}</td>
                                <td style="padding: 3px" >
                                    <div >
                                        {$v.sort}
                                    </div>
                                </td>

                                <td>
                                    <a href="{:url('add_edu',['pid'=>$v.id])}" class="btn btn-primary btn-xs">
                                        <i class="fa fa-plus"></i></a>&nbsp;&nbsp;
                                </td>


                                <td>

                                    <a href="{:url('edu_edit',['id'=>$v.id])}" class="btn btn-primary btn-xs">
                                        <i class="fa fa-paste"></i> 编辑</a>&nbsp;&nbsp;
                                    <a href="javascript:;" onclick="del_edu({$v.id})" class="btn btn-danger btn-xs">
                                        <i class="fa fa-trash-o"></i> 删除</a>
                                </td>
                            </tr>
                            {/foreach}
                            <tr>
                                <!--<td colspan="8" align="right">-->
                                    <!--<button type="submit"  id="btnorder" class="btn btn-info">更新排序</button></td>-->
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

</div>
{include file="public/footer" /}

<script type="text/javascript">

    $(function(){
        $('#add_edu').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#title').val())){
                layer.msg('请输入机构名称',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }

            if( '' == $.trim($('#name').val())){
                layer.msg('控制器/方法不能为空',{icon:0,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }


        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('menu/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1});
                return false;
            }
        }

    });


    //更新排序
    $(function(){
        $('#eduorder').ajaxForm({
            success: complete,
            dataType: 'json'
        });

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 1,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('menu/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                    window.location.href=data.url;
                });
            }
        }
    });


    /**
     * [del_edu 删除机构]
     * @Author[田建龙 864491238@qq.com]
     * @param   {[type]}    id [用户id]
     */
    function del_edu(id){
        layer.confirm('确认删除此机构?', {icon: 3, title:'提示'}, function(index){
            //do something
            $.getJSON('./del', {'id' : id}, function(res){
                if(res.code == 1){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(index){
                        layer.close(index);
                        window.location.href="{:url('instit/edu')}";
                    });

                }else{
                    layer.msg(res.msg,{icon:0,time:1500,shade: 0.1});
                }
            });

            layer.close(index);
        })

    }

    //机构状态
    function edu_state(id){
        lunhui.status(id,'{:url("instit_state")}');
    }

    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }
</script>
</body>
</html>